// PendingIssueServiceImpl.java
package com.bolingcavalry.crm.pendingissue.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.bolingcavalry.crm.pendingissue.mapper.PendingIssueMapper;
import com.bolingcavalry.crm.pendingissue.service.PendingIssueService;
import com.entity.pendingissue.PendingIssue;
import org.springframework.stereotype.Service;

@Service
public class PendingIssueServiceImpl extends ServiceImpl<PendingIssueMapper, PendingIssue> implements PendingIssueService {

    @Override
    public IPage<PendingIssue> getByConditions(Integer pageNum, Integer pageSize, String customerCompanyName, String serviceLocation, String issueCategory) {
        QueryWrapper<PendingIssue> queryWrapper = new QueryWrapper<>();

        // 添加查询条件
        if (customerCompanyName != null && !customerCompanyName.isEmpty()) {
            queryWrapper.like("customer_company_name", customerCompanyName);
        }
        if (serviceLocation != null && !serviceLocation.isEmpty()) {
            queryWrapper.like("service_location", serviceLocation);
        }
        if (issueCategory != null && !issueCategory.isEmpty()) {
            queryWrapper.like("issue_category", issueCategory);
        }

        // 按创建时间倒序排列
        queryWrapper.orderByDesc("create_time");

        // 执行分页查询
        Page<PendingIssue> page = new Page<>(pageNum, pageSize);
        return this.page(page, queryWrapper);
    }
}
